#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# 新增运营机型设备 例子
# @Time    : 2021/12/23 下午8:20
# @Author  : luowenjie
import requests

username = ""
password = ""
url = "http://beta-mgr.device.skysrt.com/"
loginPath = "login"
addPath = "device/adevice/add"
selectPath = "device/adevice/getAdeviceSelect"
pendingAuditPath = "device/adevice/pendingAudit"
auditPath = "/device/adevice/audit"

# 登录接口
def doLogin():
    header = {
        "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36"
    }
    data = {
        "loginName": username,
        "password": password
    }
    api = url + loginPath
    s = requests.Session()
    r = s.post(api, data)
    return s;


# 新增或修改运营机型设备
def addDevice(session):
    """
    简要描述方法的用途。

    参数:
        param1 (type1): 描述参数1的用途。
        param2 (type2): 描述参数2的用途。
        ...
        paramN (typeN): 描述参数N的用途。

    返回:
        type: 描述返回值的意义。

    异常:
        ErrorType: 描述可能抛出的错误及条件。

    例子:
        >>> function_name('example', 1)
        'return_value'
    """
    api = url + addPath
    payload = 'tvCameraPosition=1&' \
              'tvCamera=1&' \
              'tvCameraPixel=22222&' \
              'tvCameraSupplier=1&' \
              'roProductDevice=123123&' \
              'cooCaaSharedScreen=0&' \
              'tVOwner=&id=1651&' \
              'model=3213&' \
              'curAuditStatus=1&' \
              'chip=12312&' \
              'brandId=35&' \
              'brandName=%E5%B0%8F%E5%BA%A6&' \
              'androidVersionValue=4.3&' \
              'androidVersionLabel=Android%204.3&' \
              'chipProviderValue=amlogic&' \
              'chipProviderLabel=Amlogic&' \
              'chipId=45&' \
              'chipName=7366M6L&' \
              'tvScreenSizeValues=27%2C24%2C21%2C82%2C77%2C98&' \
              'tvScreenSizeLabels=27%2C24%2C21%2C82%2C77%2C98&' \
              'tvScreenResolutionValue=720p&' \
              'tvScreenResolutionLabel=720P&' \
              'tvScreenTypeValue=%E6%BF%80%E5%85%89&' \
              'tvScreenTypeLabel=%E6%BF%80%E5%85%89&' \
              'tvIsOled=0&' \
              'tvStorageEmmcSizeValue=64g&' \
              'tvStorageEmmcSizeLabel=64G&' \
              'tvStorageRamSizeValue=3g&' \
              'tvStorageRamSizeLabel=3G&' \
              'wifiId=27&' \
              'wifiModelName=ATBM6032&' \
              'tvIsSupport2_4g=1&' \
              'bluetoothId=12&b' \
              'luetoothModel=MT7638GU&' \
              'remoteControlId=53&' \
              'remoteControlModel=%E9%A3%9E%E5%88%A9%E6%B5%A6%E6%99%BA%E6%85%A7%E6%A3%92%E9%81%A5%E6%8E%A7%E5%99%A8&' \
              'HDMI1_4=3&' \
              'HDMI2_0=2&' \
              'USB2_0=2&' \
              'USB3_0=3&' \
              'AV_in=1&' \
              'AV_out=2&' \
              'tvPeripheraInputCheckboxValues=rj45%2Crf_in%2Cspdif%2Ctf_card_slot&' \
              'tvPeripheraInputCheckboxLabels=%E6%9C%89%E7%BA%BF%E7%BD%91%E7%BB%9C%E6%8E%A5%E5%8F%A3%2CRF%E5%B0%84%E9%A2%91%E8%BE%93%E5%85%A5%EF%BC%88%E9%AB%98%E9%A2%91%E5%A4%B4%EF%BC%89%2CSPDIF%2CTF%E5%8D%A1%E6%A7%BD&' \
              'tvUiResolutionValue=2160P&' \
              'tvUiResolutionLabel=2160P&' \
              'tvHomePageValue=8_x_standard_hp&' \
              'tvHomePageLabel=8.0%E4%B8%BB%E9%A1%B5&' \
              'contentSourceId=1&' \
              'contentSourcesName=%E8%85%BE%E8%AE%AF&' \
              'licenseSourceId=1&' \
              'licenseSourcesName=%E6%97%A0%E7%89%8C%E7%85%A7&' \
              'tvContentSourceSupportValues=4_K%2CH_D_R_zuan_qu%2C3_D%2Cwu%2Cdolby_atmos%2Cdolby_vision&' \
              'tvContentSourceSupportLabels=4K%2CHDR%E4%B8%93%E5%8C%BA%2C3D%2C%E6%97%A0%2C%E6%9D%9C%E6%AF%94%E5%85%A8%E6%99%AF%E5%A3%B0%2C%E6%9D%9C%E6%AF%94%E8%A7%86%E7%95%8C&' \
              'tvGeneralSoftwareConfigValues=&' \
              'tvAdvanceSoftwareConfigValues=&' \
              'tvMechanicalKey=&' \
              'tvImageQualityValues=4k2k_h_265_60fbp%2C4k2k_h_265_30fbp&' \
              'tvImageQualityLabels=4K2K%20H.265%2060fbp%2C4K2K%20H.265%2030fbp&' \
              'tvSoundQualityValues=jbl_sound_effects%2Csurround_sound&' \
              'tvSoundQualityLabels=JBL%E9%9F%B3%E6%95%88%2C%E7%8E%AF%E7%BB%95%E5%A3%B0&' \
              'tvCertificationValues=dolby_vision%2Cdrm%2Chdr_10&' \
              'tvCertificationLabels=Dolby%20Vision%2CDRM%2CHDR10&' \
              'tvOther=123123123&' \
              'tvDistributionChannel=e-commerce&' \
              'tvSalesName=%E7%94%B5%E5%95%86&' \
              'devType=4K%20monitor&' \
              'devTypeName=4K%E7%9B%91%E8%A7%86%E5%99%A8&' \
              'tvIsDerive=1&' \
              'shieldApplicationsAutoUpdate=0&' \
              'tvDeriveFrom=1650&' \
              'tvFunctionSupport=video_call%2Csmart_home%2Cvisible_chat%2Cmall_remote_control%2Cis_support_str_standby%2Chdmi-arc&' \
              'tvFunctionSupportLabels=%E8%A7%86%E9%A2%91%E9%80%9A%E8%AF%9D%2C%E6%99%BA%E6%85%A7%E5%AE%B6%E5%BA%AD%2C%E8%A7%86%E9%A2%91%E8%81%8A%E5%A4%A9%2C%E5%8D%96%E5%9C%BA%E9%81%A5%E6%8E%A7%E5%99%A8%2CSTR%E5%BE%85%E6%9C%BA%2CHDMI%20ARC&' \
              'tvPeripheralDriver=camera_driver%2Cmall_remote_control&' \
              'tvPeripheralDriverLabels=%E6%91%84%E5%83%8F%E5%A4%B4%E9%A9%B1%E5%8A%A8%2C%E5%8D%96%E5%9C%BA%E9%81%A5%E6%8E%A7%E5%99%A8&' \
              'tvDemoFunction=epop%2Cmall&' \
              'tvDemoFunctionLabels=EPOP%E6%BC%94%E7%A4%BA%2C%E5%95%86%E5%9C%BA%E6%BC%94%E7%A4%BA&' \
              'tvOtherFunction=tieline%2Ccamera%2Ctf-sd-card%2C2.4g-microphone&' \
              'tvOtherFunctionLabels=%E6%A0%87%E9%85%8D%E8%BD%AC%E6%8E%A5%E7%BA%BF%2C%E6%A0%87%E9%85%8D%E6%91%84%E5%83%8F%E5%A4%B4%2C%E6%A0%87%E9%85%8DTF%2FSD%E5%8D%A1%2C%E6%A0%87%E9%85%8D2.4G%E9%BA%A6%E5%85%8B%E9%A3%8E&' \
              'powerStartAd=global_popup%2Capplication%2Cclose&' \
              'powerStartAdLabels=%E6%94%AF%E6%8C%81%E5%85%A8%E5%B1%80%E5%BC%B9%E7%AA%97%2C%E6%94%AF%E6%8C%81%E5%BA%94%E7%94%A8%E5%90%AF%E5%8A%A8%E5%B9%BF%E5%91%8A%2C%E6%94%AF%E6%8C%81%E5%85%B3%E6%9C%BA%E5%B9%BF%E5%91%8A&' \
              'closeLoopProductionDate=2021-12-21&' \
              'tvContentSourceSupportStr=4K%E3%80%81HDR%E4%B8%93%E5%8C%BA%E3%80%813D%E3%80%81%E6%97%A0%E3%80%81%E6%9D%9C%E6%AF%94%E5%85%A8%E6%99%AF%E5%A3%B0%E3%80%81%E6%9D%9C%E6%AF%94%E8%A7%86%E7%95%8C&' \
              'curAuditStatus=1&' \
              'auditStatus=1&' \
              'auditStatusFlag=true'
    headers = {
        'Content-Type': 'application/x-www-form-urlencoded',
    }
    response = session.request("POST", api, headers=headers, data=payload)
    print(response.text)


# 获取下拉框数据
def getDeviceSelect(session):
    api = url + selectPath
    payload = {}
    headers = {
    }
    response = session.request("GET", api, headers=headers, data=payload)

    print(response.text)


# 提交审核 并且保存  auditStatus要设为2
def pendingAudit(session):
    api = url + pendingAuditPath
    payload = 'tvCameraPosition=1&' \
              'tvCamera=1&' \
              'tvCameraPixel=22222&' \
              'tvCameraSupplier=1&' \
              'roProductDevice=123123&' \
              'cooCaaSharedScreen=0&' \
              'tVOwner=&id=1651&' \
              'model=3213&' \
              'curAuditStatus=1&' \
              'chip=12312&' \
              'brandId=35&' \
              'brandName=%E5%B0%8F%E5%BA%A6&' \
              'androidVersionValue=4.3&' \
              'androidVersionLabel=Android%204.3&' \
              'chipProviderValue=amlogic&' \
              'chipProviderLabel=Amlogic&' \
              'chipId=45&' \
              'chipName=7366M6L&' \
              'tvScreenSizeValues=27%2C24%2C21%2C82%2C77%2C98&' \
              'tvScreenSizeLabels=27%2C24%2C21%2C82%2C77%2C98&' \
              'tvScreenResolutionValue=720p&' \
              'tvScreenResolutionLabel=720P&' \
              'tvScreenTypeValue=%E6%BF%80%E5%85%89&' \
              'tvScreenTypeLabel=%E6%BF%80%E5%85%89&' \
              'tvIsOled=0&' \
              'tvStorageEmmcSizeValue=64g&' \
              'tvStorageEmmcSizeLabel=64G&' \
              'tvStorageRamSizeValue=3g&' \
              'tvStorageRamSizeLabel=3G&' \
              'wifiId=27&' \
              'wifiModelName=ATBM6032&' \
              'tvIsSupport2_4g=1&' \
              'bluetoothId=12&b' \
              'luetoothModel=MT7638GU&' \
              'remoteControlId=53&' \
              'remoteControlModel=%E9%A3%9E%E5%88%A9%E6%B5%A6%E6%99%BA%E6%85%A7%E6%A3%92%E9%81%A5%E6%8E%A7%E5%99%A8&' \
              'HDMI1_4=3&' \
              'HDMI2_0=2&' \
              'USB2_0=2&' \
              'USB3_0=3&' \
              'AV_in=1&' \
              'AV_out=2&' \
              'tvPeripheraInputCheckboxValues=rj45%2Crf_in%2Cspdif%2Ctf_card_slot&' \
              'tvPeripheraInputCheckboxLabels=%E6%9C%89%E7%BA%BF%E7%BD%91%E7%BB%9C%E6%8E%A5%E5%8F%A3%2CRF%E5%B0%84%E9%A2%91%E8%BE%93%E5%85%A5%EF%BC%88%E9%AB%98%E9%A2%91%E5%A4%B4%EF%BC%89%2CSPDIF%2CTF%E5%8D%A1%E6%A7%BD&' \
              'tvUiResolutionValue=2160P&' \
              'tvUiResolutionLabel=2160P&' \
              'tvHomePageValue=8_x_standard_hp&' \
              'tvHomePageLabel=8.0%E4%B8%BB%E9%A1%B5&' \
              'contentSourceId=1&' \
              'contentSourcesName=%E8%85%BE%E8%AE%AF&' \
              'licenseSourceId=1&' \
              'licenseSourcesName=%E6%97%A0%E7%89%8C%E7%85%A7&' \
              'tvContentSourceSupportValues=4_K%2CH_D_R_zuan_qu%2C3_D%2Cwu%2Cdolby_atmos%2Cdolby_vision&' \
              'tvContentSourceSupportLabels=4K%2CHDR%E4%B8%93%E5%8C%BA%2C3D%2C%E6%97%A0%2C%E6%9D%9C%E6%AF%94%E5%85%A8%E6%99%AF%E5%A3%B0%2C%E6%9D%9C%E6%AF%94%E8%A7%86%E7%95%8C&' \
              'tvGeneralSoftwareConfigValues=&' \
              'tvAdvanceSoftwareConfigValues=&' \
              'tvMechanicalKey=&' \
              'tvImageQualityValues=4k2k_h_265_60fbp%2C4k2k_h_265_30fbp&' \
              'tvImageQualityLabels=4K2K%20H.265%2060fbp%2C4K2K%20H.265%2030fbp&' \
              'tvSoundQualityValues=jbl_sound_effects%2Csurround_sound&' \
              'tvSoundQualityLabels=JBL%E9%9F%B3%E6%95%88%2C%E7%8E%AF%E7%BB%95%E5%A3%B0&' \
              'tvCertificationValues=dolby_vision%2Cdrm%2Chdr_10&' \
              'tvCertificationLabels=Dolby%20Vision%2CDRM%2CHDR10&' \
              'tvOther=123123123&' \
              'tvDistributionChannel=e-commerce&' \
              'tvSalesName=%E7%94%B5%E5%95%86&' \
              'devType=4K%20monitor&' \
              'devTypeName=4K%E7%9B%91%E8%A7%86%E5%99%A8&' \
              'tvIsDerive=1&' \
              'shieldApplicationsAutoUpdate=0&' \
              'tvDeriveFrom=1650&' \
              'tvFunctionSupport=video_call%2Csmart_home%2Cvisible_chat%2Cmall_remote_control%2Cis_support_str_standby%2Chdmi-arc&' \
              'tvFunctionSupportLabels=%E8%A7%86%E9%A2%91%E9%80%9A%E8%AF%9D%2C%E6%99%BA%E6%85%A7%E5%AE%B6%E5%BA%AD%2C%E8%A7%86%E9%A2%91%E8%81%8A%E5%A4%A9%2C%E5%8D%96%E5%9C%BA%E9%81%A5%E6%8E%A7%E5%99%A8%2CSTR%E5%BE%85%E6%9C%BA%2CHDMI%20ARC&' \
              'tvPeripheralDriver=camera_driver%2Cmall_remote_control&' \
              'tvPeripheralDriverLabels=%E6%91%84%E5%83%8F%E5%A4%B4%E9%A9%B1%E5%8A%A8%2C%E5%8D%96%E5%9C%BA%E9%81%A5%E6%8E%A7%E5%99%A8&' \
              'tvDemoFunction=epop%2Cmall&' \
              'tvDemoFunctionLabels=EPOP%E6%BC%94%E7%A4%BA%2C%E5%95%86%E5%9C%BA%E6%BC%94%E7%A4%BA&' \
              'tvOtherFunction=tieline%2Ccamera%2Ctf-sd-card%2C2.4g-microphone&' \
              'tvOtherFunctionLabels=%E6%A0%87%E9%85%8D%E8%BD%AC%E6%8E%A5%E7%BA%BF%2C%E6%A0%87%E9%85%8D%E6%91%84%E5%83%8F%E5%A4%B4%2C%E6%A0%87%E9%85%8DTF%2FSD%E5%8D%A1%2C%E6%A0%87%E9%85%8D2.4G%E9%BA%A6%E5%85%8B%E9%A3%8E&' \
              'powerStartAd=global_popup%2Capplication%2Cclose&' \
              'powerStartAdLabels=%E6%94%AF%E6%8C%81%E5%85%A8%E5%B1%80%E5%BC%B9%E7%AA%97%2C%E6%94%AF%E6%8C%81%E5%BA%94%E7%94%A8%E5%90%AF%E5%8A%A8%E5%B9%BF%E5%91%8A%2C%E6%94%AF%E6%8C%81%E5%85%B3%E6%9C%BA%E5%B9%BF%E5%91%8A&' \
              'closeLoopProductionDate=2021-12-21&' \
              'tvContentSourceSupportStr=4K%E3%80%81HDR%E4%B8%93%E5%8C%BA%E3%80%813D%E3%80%81%E6%97%A0%E3%80%81%E6%9D%9C%E6%AF%94%E5%85%A8%E6%99%AF%E5%A3%B0%E3%80%81%E6%9D%9C%E6%AF%94%E8%A7%86%E7%95%8C&' \
              'auditStatus=2'
    headers = {
        'Content-Type': 'application/x-www-form-urlencoded',
    }

    response = session.request("POST", api, headers=headers, data=payload)

    print(response.text)


# 进行审核
def audit(session):

    api = url + auditPath

    payload = 'ids=1650%2C1651&auditStatus=4&auditReason=%E9%80%9A%E8%BF%87'
    headers = {
        'Content-Type': 'application/x-www-form-urlencoded',
    }

    response = session.request("POST", api, headers=headers, data=payload)

    print(response.text)


if __name__ == '__main__':
    # 登录接口
    session = doLogin()

    # 获取下拉框数据
    getDeviceSelect(session)

    # 新增或修改运营机型设备
    addDevice(session)

    # 提交审核 并且保存  auditStatus要设为2
    pendingAudit(session)

    # 进行审核
    audit(session)
